package com.jmz.apt.api.Provider;

import com.jmz.apt.api.entity.IEntity;
import com.jmz.apt.api.entity.dbEntity.JmzAdminRoleResource;
import com.jmz.apt.api.entity.dbEntity.JmzAdminUser;
import com.jmz.apt.api.message.request.Condition;
import com.jmz.apt.api.message.request.Query;
import com.jmz.apt.api.message.request.RequestMessage;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;

/**
 * Created by fanglexue on 2019/10/28.
 */
public class AdminRoleResProvider extends BaseProvider {


    public String getCount(List<Condition> conditions) {
        return super.count(conditions);
    }

    public String select(String columns, List<Condition> conditions, Query query) {
        return  super.findAll(columns,conditions,query);
    }

    public String getTableName(){
        return "jmz_admin_role_resource";
    }

    /**
    //插入
    public String insert(RequestMessage requestMessage) {
        List<IEntity> entities = super.mapDataSet(requestMessage);
        JmzAdminRoleResource jmzAdminRoleResource = (JmzAdminRoleResource)entities.get(0);
        SQL sql = new SQL();
        sql.INSERT_INTO("jmz_admin_user");

        if (jmzAdminRoleResource.getResourceId() != null) {
            sql.VALUES("resource_id", "#{resource_id}");
        }

        if (jmzAdminRoleResource.getRoleId() != null) {
            sql.VALUES("role_id", "#{role_id}");
        }

        return sql.toString();
    }

    public String delete(RequestMessage requestMessage) {
        List<IEntity> entities = super.mapDataSet(requestMessage);
        JmzAdminRoleResource  jmzAdminRoleResource = (JmzAdminRoleResource)entities.get(0);
        return new SQL() {{
            DELETE_FROM("student");
            if (jmzAdminRoleResource.getId() != null) {
                WHERE("id = #{id}");
            }
        }}.toString();
    }

    //更新
    public String update(RequestMessage requestMessage) {
        List<IEntity> entities = super.mapDataSet(requestMessage);
        JmzAdminRoleResource  jmzAdminRoleResource = (JmzAdminRoleResource)entities.get(0);
        return new SQL() {{
            UPDATE("student");
            if (jmzAdminRoleResource.getRoleId() != null) {
                SET("name = #{role_id}");
            }
            if (jmzAdminRoleResource.getResourceId() != null) {
                SET("resource_id = #{resource_id}");
            }
            WHERE("id = #{id}");
        }}.toString();
    }
     **/

}
